package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "hello go"
	//判断字符串s是否包含子串 go
	r := strings.Contains(s, "go")
	fmt.Println(r) //true

	//判断子串第一次出现的位置，不存在返回-1
	index := strings.Index(s, "go")
	fmt.Println(index) //6

	//类型PHP中的implode，将切片转成逗号分隔的字符串
	arr := []string{"a", "1", "3", "b"}
	str := strings.Join(arr, ",")
	fmt.Println(str)

	//类型PHP中的explode，将逗号分隔的字符串，转成切片
	names := "tom,jim,Lee"
	nameArr := strings.Split(names, ",")
	fmt.Println(nameArr)

	//字符串替换
	msg := " have a good weekend  "
	//第一个参数：原字符串。第二个参数：要搜索和替换的字符串。第三个参数：替换为的字符串。第四个参数：替换几次。-1代表全部替换
	new := strings.Replace(msg, " ", "-", -1)
	fmt.Println(msg) //不会改变
	fmt.Println(new)

	//空格去除
	msg2 := strings.Trim(msg, " ")
	fmt.Println(msg2)
}
